package com.cf.game.node;

import com.cf.constant.EnumReturnCode;
import com.cf.exception.BizException;
import org.apache.commons.lang3.StringUtils;

/**
 * boot-awm-Node
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/27 上午 11:17
 */
public class Node {

    private String name;

    private String parentPath = "/";

    public String getPath() {
        if (StringUtils.isEmpty(parentPath))
            throw new BizException(EnumReturnCode.ERROR.getCode(), "根路径不存在！");
        if (parentPath.lastIndexOf("/") != (parentPath.length() - 1)) {
            return parentPath + "/" + name;
        }
        return parentPath + name;
    }


    public static Node instance(String name, String parentPath) {
        return new Node(name, parentPath);
    }

    public Node(String name, String parentPath) {
        this.name = name;
        this.parentPath = parentPath;
    }

    public String getParentPath() {
        return parentPath;
    }

    public void setParentPath(String parentPath) {
        this.parentPath = parentPath;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
